package com.coldchain.admin.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.coldchain.admin.user.entity.Admin;
import com.coldchain.admin.user.mapper.AdminMapper;
import com.coldchain.admin.user.service.IAdminService;
import com.coldchain.admin.user.service.IRoleService;
import com.coldchain.vo.AdminVo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 管理员表 服务实现类
 * </p>
 *
 * @author fangliai
 * @since 2018-08-30
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements IAdminService {
    private static Logger log= LoggerFactory.getLogger(AdminServiceImpl.class);

    @Autowired
    private IRoleService roleService;

    @Override
    public List<AdminVo> getAdminVo() {
        List<AdminVo> adminVos=baseMapper.getAdminVo();
        adminVos.forEach((v->{
            if(!StringUtils.isEmpty(v.getRolestr())){
                QueryWrapper queryWrapper=new QueryWrapper();
                queryWrapper.in("id",StringUtils.split(v.getRolestr(),","));
                v.setRoles(roleService.list(queryWrapper));
            }
        }));
        return adminVos;
    }
}
